package com.hex.ds.hdtp.core.app.script.test.service.impl;

import com.hex.ds.hdtp.core.app.common.page.PageData;
import com.hex.ds.hdtp.core.app.common.page.converter.IPageAndPageDtoConverter;
import com.hex.ds.hdtp.core.app.common.page.dto.PageDto;
import com.hex.ds.hdtp.core.app.script.test.converter.IScriptTestDataAnalysisConverter;
import com.hex.ds.hdtp.core.app.script.test.dto.request.ScriptTestDataAnalysisRequestDto;
import com.hex.ds.hdtp.core.app.script.test.dto.response.ScriptTestDataAnalysisResponseDto;
import com.hex.ds.hdtp.core.app.script.test.service.IScriptTestDataAnalysisService;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.script.test.po.ScriptTestDataAnalysisPo;
import com.hex.ds.hdtp.core.inf.script.test.repository.IScriptTestDataAnalysisRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Package: com.hex.ds.hdtp.core.app.script.test.service.impl
 * @ClassName ScriptTestDataAnalysisService
 * @Description: 带数据脚本测试数据分析结果-业务接口实现
 * @Author: wz.li
 * @Date 2023/8/1 16:40
 * @Version v2.0.2
 **/
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ScriptTestDataAnalysisService implements IScriptTestDataAnalysisService {

    private final IScriptTestDataAnalysisRepository scriptTestDataAnalysisRepository;

    private final IScriptTestDataAnalysisConverter converter;

    private final IPageAndPageDtoConverter pageAndPageDtoConverter;

    /*
     * @Method: queryListByPage <br>
     * @Param: [scriptTestDataAnalysisRequestDto, pageDto] <br>
     * @Return: com.hex.ds.hdtp.core.app.common.page.PageData <br>
     * @Description：分页查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 16:43 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public PageData queryListByPage(ScriptTestDataAnalysisRequestDto scriptTestDataAnalysisRequestDto, PageDto pageDto) {
        final Page<ScriptTestDataAnalysisPo> pageResult = scriptTestDataAnalysisRepository.queryListByPage(
                converter.toScriptTestDataAnalysisPo(scriptTestDataAnalysisRequestDto), pageAndPageDtoConverter.toPage(pageDto));
        List<ScriptTestDataAnalysisResponseDto> responseDtos = converter.toScriptTestDataAnalysisResponseDtoList(pageResult.getData());
        return new PageData(responseDtos, pageResult.getTotal());
    }

    /*
     * @Method: queryList <br>
     * @Param: [scriptTestDataAnalysisRequestDto] <br>
     * @Return: java.util.List<com.hex.ds.hdtp.core.app.script.test.dto.response.ScriptTestDataAnalysisResponseDto> <br>
     * @Description：不分页查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 16:43 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public List<ScriptTestDataAnalysisResponseDto> queryList(ScriptTestDataAnalysisRequestDto scriptTestDataAnalysisRequestDto) {
        final List<ScriptTestDataAnalysisPo> scriptTestDataAnalysisPos = scriptTestDataAnalysisRepository.queryList(converter.toScriptTestDataAnalysisPo(scriptTestDataAnalysisRequestDto));
        return converter.toScriptTestDataAnalysisResponseDtoList(scriptTestDataAnalysisPos);
    }

    /*
     * @Method: add <br>
     * @Param: [scriptTestDataAnalysisRequestDto] <br>
     * @Return: void <br>
     * @Description：新增<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 16:43 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public void add(ScriptTestDataAnalysisRequestDto scriptTestDataAnalysisRequestDto) {
        int count = scriptTestDataAnalysisRepository.add(converter.toScriptTestDataAnalysisPo(scriptTestDataAnalysisRequestDto));
        if (count != 1) {
            throw new RuntimeException("脚本测试数据分析结果-新增失败");
        }
    }

    /*
     * @Method: modifyById <br>
     * @Param: [scriptTestDataAnalysisRequestDto] <br>
     * @Return: void <br>
     * @Description：根据主键更新<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 16:43 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public void modifyById(ScriptTestDataAnalysisRequestDto scriptTestDataAnalysisRequestDto) {
        int count = scriptTestDataAnalysisRepository.modifyById(converter.toScriptTestDataAnalysisPo(scriptTestDataAnalysisRequestDto));
        if (count != 1) {
            throw new RuntimeException("更新脚本测试数据分析结果失败");
        }
    }

    /*
     * @Method: removeById <br>
     * @Param: [pkId] <br>
     * @Return: void <br>
     * @Description：根据主键删除<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 16:43 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public void removeById(String pkId) {
        int count = scriptTestDataAnalysisRepository.removeById(pkId);
        if (count != 1) {
            throw new RuntimeException("脚本测试数据分析结果-新增失败");
        }
    }

}
